package com.sunrise.generico.util;

import java.io.File;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;

import com.sunrise.generico.nfe.NfeProc;
import com.sunrise.generico.xml.destinatarios.Destinatarios;

public class JAXBUtil {

	public static NfeProc unmarhNFe(File file) throws JAXBException{
		JAXBContext contextJaxb;
		try {
			contextJaxb = JAXBContext.newInstance(NfeProc.class);
			Unmarshaller unmarshaller = contextJaxb.createUnmarshaller();  
			return (NfeProc) unmarshaller.unmarshal(file);
		} catch (JAXBException e) {
			throw new JAXBException("erroLeituraNFe");
		}  
	}
	
	public static Destinatarios unmarhDestinatarios(File file) throws JAXBException{
		JAXBContext contextJaxb;
		try {
			contextJaxb = JAXBContext.newInstance(Destinatarios.class);
			Unmarshaller unmarshaller = contextJaxb.createUnmarshaller();  
			return (Destinatarios) unmarshaller.unmarshal(file);
		} catch (JAXBException e) {
			throw new JAXBException("erroLeituraNFe");
		}  
	}
	
}
